checkLogin();

//获取图形验证码
$('.verify_img').attr('src',client_captcha);

$('.verify_img').bind('click',function () {
    $('.verify_img').attr('src',client_captcha);
})

var login = getCache(login_key);
var mobile = login.mobile;
if(isEmpty(mobile)){
    $('.mui-title').text('手机验证')
}else {
    //电话号码隐藏中间思维
    var mtel = mobile.substr(0, 3) + '****' + mobile.substr(7);
    $('.oldMobile').text(mtel);
    $('.old_mobile').css('display','block');
    $('.mui-title').text('修改手机验证');
}

var is_mobile = function(e) {
    var status = true;
    if (!(/^1\d{10}$/.test( $(e).val()))){
        status = false;
    }
    return {
        status: status, // or false
        message: '请填写正确的手机号'
    };
}

//修改手机时，需要填写验证码
var is_card = function () {
    var status = true;
    var message = '请填写验证码';
    //判断是否填写
    var card = $('.is_captcha').val();
    if (isEmpty(card)) {
        status = false;
    }

    return {
        status: status, // or false
        message: message
    };
}

/*$('.get_code').bind('click',function () {

    $(this).addClass('mui-disabled').attr('disabled', true);
    var mobile = $('.mobile').val();
    if (mobile == undefined || mobile == null || mobile == '') {
        malert('请填写联系方式');
        $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
        return;
    }
    var success = function (res) {
        console.log(res)
        var info = res.sms_time;

        $('.get_code').text(info + 's');
        var intervarId = null;

        function count_down() {
            info--;
            if (info <= 0) {
                clearInterval(intervarId);
                $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
                $('.get_code').text('请重新获取');
                return;
            }
            $('.get_code').text(info + 's');
        }

        intervarId = setInterval(function () {
            count_down();
        }, 1000);

    }
    getData(member_sms_captcha, combineParams({mobile: mobile,}), success);
})*/
$('.get_code').bind('click',function () {

    $(this).addClass('mui-disabled').attr('disabled', true);
    var mobile = $('.mobile').val();
    var verify = $('.verify').val();
    if(isEmpty(verify)) {
        malert('请输入图形码', '提示', '确定');
        $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
        return;
    }
    if (isEmpty(mobile)) {
        malert('请填写联系方式', '提示', '确定');
        $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
        return;
    }
    var success = function (res) {
        console.log(res)
        var info = res.sms_time;

        $('.get_code').text('等'+info + 's'+'重新获取');
        var intervarId = null;

        function count_down() {
            info--;
            if (info <= 0) {
                clearInterval(intervarId);
                $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
                $('.get_code').text('请重新获取动态码');
                return;
            }
            $('.get_code').text('等'+info + 's'+'重新获取');
        }

        intervarId = setInterval(function () {
            count_down();
        }, 1000);

    }

    getData(simple_sms, combineParams({mobile: mobile,type:2,verify:verify}), success);
})


var ajaxOption = {
    url: member_add_information,
    method: 'POST',
    data: comParams(),
    success: function (res) {
        //保存成功  将修改的电话追加到 缓存中
        var mobile = $('.mobile').val();
        var login_text = getCache(login_key);
        if(!isEmpty(login_text) && isEmpty(login_text.mobile)){
            login_text.mobile = mobile;
            console.log(login_text)
            setCache(login_key, login_text);
        }
        redirect('member.html');
    }
}

checkform($('#myform'), ajaxOption);

